package com.guoxue.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.guoxue.dao.IDistrictDao;
import com.guoxue.domain.DistrictVo;
@Repository
public class DistrictDaoImpl extends BaseDaoImpl<DistrictVo> implements IDistrictDao{

	@Override
	public void saveDistrict(DistrictVo dt) {
		saveOrUpdate(dt);
	}

	@Override
	public List<DistrictVo> getDistrictList() {
		return find("From DistrictVo");
	}

	@Override
	public void deleteDistrict(int id) {
		executeHql("DELETE FROM DistrictVo d WHERE d.id=?", new Object[] {id});
	}

	@Override
	public DistrictVo getDistrictByKey(int district) {
		return get("FROM DistrictVo d WHERE d.id=? AND d.sysflag=0", new Object[] {district});
	}

	@Override
	public List<DistrictVo> getSchoolList(String city, String province, String county) {
		return find("FROM DistrictVo d WHERE d.city=? AND d.province=? AND d.county=? AND d.sysflag=0 GROUP BY d.school",new Object[] {city,province,county});
	}

	@Override
	public DistrictVo searchDistrict(String[] dis) {
		DistrictVo d = null;
		if (dis.length==3){
		 d = get("FROM DistrictVo d WHERE d.province=? AND d.city=? AND d.county=? AND d.sysflag=0",new Object[]{dis[0],dis[1],dis[2]});
		}
		if (dis.length==4){
		 d = get("FROM DistrictVo d WHERE d.province=? AND d.city=? AND d.county=? AND d.school=? AND d.sysflag=0",new Object[]{dis[0],dis[1],dis[2],dis[3]}); 
		}
		return d;
	}

}
